/**求购商品列表页面 */
//未完成：分页，没有数据，下拉加载，加载完成。。。
var basePage = require('../../../common/BasePage');
var baseList = require('../../../common/BaseList');
Page({
    behaviors: [basePage, baseList],
    data: {
        search: '',
        reqUrl: "/home/product/items",
        searchId: 0,
        /**页面类型 */
        typeArr: [{
                reqUrl: "/home/product/items",
                title: "选择商品",
                client: ''
            },
            {
                reqUrl: "/home/staff/express/user",
                title: "请选择用户",
                client: 'express'
            },
        ],
        /**0：搜索商品，1：搜索用户 */
        type: 0,
    },
    onLoad(data) {
        data.wh_id ? this.data.reqData.wh_id = data.wh_id : "";
        //判断页面类型，访问不同内容
        if (data.type) {
            this.setData({
                type: data.type
            })
            // this.data.type=data.type;
            let obj = this.data.typeArr[data.type];
            this.data.reqUrl = obj.reqUrl;
            this.data.client = obj.client;
            wx.setNavigationBarTitle({
                title: obj.title,
            })
        } else {
            this.req_items();
        }

        // this.login_reload();
    },
    /**
     * 请求产品列表
     */
    // login_reload(){
    //   this.request({
    //     url: this.data.host + '/home/product/items?so='+this.data.search
    //   }, this.get_pdc_ok); 
    // },
    init_val(val, index, arr) {
        this.data.type == 0 ? val.thumb = this.get_thumb(val.product_img) : val.thumb = this.get_thumb(val.face);
        // console.log("val.thumb",val.thumb);
    },
    // get_pdc_ok(res){
    //     console.log("get_pdc_ok",res);
    //     res.data.map(val=>{
    //         val.thumb=this.get_thumb(val.product_img);
    //         // console.log("val.thumb",val.thumb);
    //       })
    //     this.setData({
    //         pdcArr:res.data,
    //     });
    // },
    search_change({
        detail
    }) {
        // console.log("search_change", detail);
        if (this.data.searchId) {
            clearTimeout(this.data.searchId);
        }
        if (this.data.type * 1 == 1 && !detail) {
            return; //只能通过有效搜索词获取用户
        }
        this.data.searchId = setTimeout(() => {
            console.log("执行搜索");
            this.data.searchId = 0;
            this.data.reqData.so = detail;
            this.data.current_page = 0;
            this.req_items();

        }, 1000);

    },
    choosegoods(e) {
        let {
            index
        } = e.mark;
        console.log("choosegoods", this.data.itemArr);
        const eventChannel = this.getOpenerEventChannel()
        eventChannel.emit('choose_pdc', this.data.itemArr[index]);
        wx.navigateBack({
            delta: 1,
        })

    }
})